package newDecoupling.service.impl;

import jakarta.annotation.Resource;
import newDecoupling.dao.HeroDao;
import newDecoupling.projo.Hero;
import newDecoupling.service.HeroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


//@Repository
@Component
//@Service
public class HeroServiceImpl2 implements HeroService {

    @Autowired
    private HeroDao heroDao;

//    @Resource(name = "heroDao")
//    private HeroDao heroDao;


    @Override
    public List<Hero> selectList() {
        List<Hero> list = heroDao.findAll().stream().map(line ->
        {
            String[] split = line.split(",");
            Integer id = Integer.parseInt(split[0]);
            String name = split[1];
            String password = split[2];
            String nickname = split[3];
            Integer age = Integer.parseInt(split[4]);
            LocalDateTime updateTime = LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new Hero(id + 100, name, password, nickname, age, updateTime);
        }).toList();

        return list;
    }

}
